package com.sias.bootdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sias.bootdemo.common.Code;
import com.sias.bootdemo.common.Result;
import com.sias.bootdemo.pojo.Book;
import com.sias.bootdemo.service.BookService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/book")
public class Controller {

    @Autowired
    private BookService bookService;

    @PostMapping("/getPage")
    public Result getAll(@RequestBody Book book) {
        IPage page = new Page(book.getCurrentPage(), book.getPageSize());
        QueryWrapper<Book> brandQueryWrapper = new QueryWrapper<>();
        brandQueryWrapper.like(book.getName() != null && !book.getName().equals(""), "name", book.getName());
        brandQueryWrapper.like(book.getType() != null && !book.getType().equals(""), "type", book.getType());
        bookService.page(page, brandQueryWrapper);
        return new Result(Code.GET_OK, page, "");
    }

}
